﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Spring.Transaction.Interceptor;

using Ic.Model;
using Ic.Dao;

namespace Ic.Services.band
{
    public class bandServices
    {
        #region 注入对象

        private IDaoSpring _DaoSpring;
        public IDaoSpring DaoSpring
        {
            get { return _DaoSpring; }
            set { _DaoSpring = value; }
        }

        #endregion        
        
        public string transactionInsert(int nums)
        {
            DateTime t1 = DateTime.Now;
            bool success = true;
            string result = string.Empty;
            IList<BandUser> list = new List<BandUser>();
            for (int i = 1; i <= nums; i++)
            {
                string t = "User_" + string.Format("{0:000000}", i);
                BandUser u = new BandUser()
                {
                    BlockExpire = DateTime.MaxValue,
                    BlockReason = string.Empty,
                    IsBlock = false,
                    RegDate = DateTime.Now,
                    UpdateDate = DateTime.Now,
                    UserBirthDate = DateTime.Now,
                    UserCity = (i % 2 == 0 ? "娄底" : "北京"),
                    UserEmail = t + "@user.com",
                    UserIntro = t,
                    UserPhoto = t + ".jpg",
                    UserProvince = (i % 2 == 0 ? "湖南" : "北京"),
                    UserSex = (i % 2 == 0 ? "男" : "女"),
                    UserLogonName = t,
                    UserTrueName = t,
                    UserPwd = "system"
                };
                list.Add(u);
            }

            success = DaoSpring.BatchSave<BandUser>(list);
            TimeSpan sp = DateTime.Now.Subtract(t1);
            if (success)
                result = sp.TotalSeconds.ToString() + "秒";
            else
                result = "失败," + DaoSpring.GetMessage();

            return result;
        }

    }
}
